package com.koron.standard.config;

import com.koron.standard.handler.UserInfoInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebConfig
 * @description
 * @Author zhouj
 * @Date 2021/5/8 10:21
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 解决swagger被拦截的问题
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("/temp/**")
                .addResourceLocations("file:"+ System.getProperty("user.dir") +"/temp/");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册UserInfoInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(new UserInfoInterceptor());
        registration.addPathPatterns("/**");  //所有路径都被拦截
    }
}
